package com.cswangdao.controller.user;

import com.cswangdao.domain.dto.WXOrderSubmitDTO;
import com.cswangdao.domain.dto.WXRefundDTO;
import com.cswangdao.domain.model.MarketOrder;
import com.cswangdao.domain.vo.WXOrderListVo;
import com.cswangdao.result.PageResult;
import com.cswangdao.result.Result;
import com.cswangdao.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/wx/order")
@Slf4j
public class WxOrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public Result<Map<String, Object>> submit(@RequestBody WXOrderSubmitDTO wxOrderSubmitDTO){

        log.info("提交订单：{}", wxOrderSubmitDTO);
        Map<String, Object> result = orderService.submit(wxOrderSubmitDTO);
        return Result.success(result);
    }

    @GetMapping("list")
    public Result<PageResult<WXOrderListVo>> list(int showType,int page,int limit){
        log.info("查询用户不同状态的订单列表：showType={}, page={}, limit={}", showType, page, limit);
        Map<String, Object> map = new HashMap<>();
        map.put("showType", showType);
        map.put("page", page);
        map.put("limit", limit);
        log.info("查询用户不同状态的订单列表：{}", map);
        PageResult<WXOrderListVo> result =orderService.queryOrderByUserIdAndStatus(map);
        return Result.success(result);
    }

    @GetMapping("/detail")
    public Result<Map<String, Object>> detail(Integer orderId){
        log.info("查询订单详情：{}", orderId);
        Map<String, Object> result = orderService.queryOrderDetail(orderId);
        return Result.success(result);
    }

    @PostMapping("/cancel")
    public Result cancel(@RequestBody Map<String, Object> map){
        log.info("取消订单：{}", map.get("orderId"));
        orderService.cancelOrder(map);
        return Result.success();
    }

    @PostMapping("/refund")

    public Result refund(@RequestBody WXRefundDTO wxRefundDTO){
        log.info("退款订单：{}", wxRefundDTO);
        orderService.refundOrder(wxRefundDTO);
        return Result.success();
    }

    @PostMapping("/confirm")
    public Result confirm(@RequestBody Map<String, Object> map){
        log.info("确认订单：{}", map.get("orderId"));
        orderService.confirmOrder(map);
        return Result.success();
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody Map<String, Object> map){
        log.info("删除订单：{}", map.get("orderId"));
        orderService.deleteOrder(map);
        return Result.success();

    }

    @GetMapping("/goods")
    public Result goods(){
        return null;
    }
}
